import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/configs'
  },
  {
    path: '/configs',
    name: 'ConfigList',
    component: () => import('@/views/ConfigList.vue'),
    meta: {
      title: '配置概览'
    }
  },
  {
    path: '/config/:type',
    name: 'UniversalConfigEditor',
    component: () => import('@/views/UniversalConfigEditor.vue'),
    meta: {
      title: '配置编辑器'
    }
  },
  // 兼容性路由，重定向到通用编辑器
  {
    path: '/equipment',
    redirect: '/config/equipment'
  },
  {
    path: '/skills', 
    redirect: '/config/skill'
  },
  {
    path: '/props',
    redirect: '/config/prop'
  },
  {
    path: '/import-export',
    name: 'ImportExport',
    component: () => import('@/views/ImportExport.vue'),
    meta: {
      title: '配置导入导出'
    }
  },
  {
    path: '/validation',
    name: 'ValidationCenter',
    component: () => import('@/views/ValidationCenter.vue'),
    meta: {
      title: '配置验证中心'
    }
  },
  {
    path: '/schema-manager',
    name: 'SchemaManager',
    component: () => import('@/views/SchemaManager.vue'),
    meta: {
      title: 'Schema管理器'
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta?.title) {
    document.title = `${to.meta.title} - Bot Server 配置编辑器`
  }
  next()
})

export default router
